﻿@model EWConfigurationDefaultWebApiRouteModel
@{
    ViewBag.Title = EWWebResources.Configuration_DefaultWebApiRoute_PageTitle;
}

<fieldset class="easyweb-ewroute">
    <legend></legend>
    <div>
        @Html.LabelFor(m => m.Value.TemplateUrl, EWWebResources.Configuration_Route_Url)
        @Html.TextBoxFor(m => m.Value.TemplateUrl)
    </div>
    <div>
        @Html.LabelFor(m => m.Value.Defaults, EWWebResources.Configuration_Route_Defaults)
        <table id="@Html.IdFor(m => m.Value.Defaults)" class="ui-widget ui-helper-reset easyweb-ewsimple">
            <thead class="ui-helper-reset ui-widget-content">
                <tr>
                    <th style="width: 20%">@EWWebResources.Configuration_Route_Name</th>
                    <th>@EWWebResources.Configuration_Route_Value</th>
                    <th style="width: 20%">@EWWebResources.Configuration_Route_Optional</th>
                    <th style="width: 10em"></th>
                </tr>
            </thead>
            <tbody class="ui-helper-reset ui-widget-content"></tbody>
            <tfoot class="ui-helper-reset ui-widget-content">
                <tr>
                    <td colspan="4"><a href="javascript:void(0)" class="easyweb-ewsimple-link-button">@EWWebResources.Configuration_Route_AddDefault</a></td>
                </tr>
            </tfoot>
        </table>
    </div>
    <div>
        @Html.LabelFor(m => m.Value.Constraints, EWWebResources.Configuration_Route_Constraints)
        <table id="@Html.IdFor(m => m.Value.Constraints)" class="ui-widget ui-helper-reset easyweb-ewsimple">
            <thead class="ui-helper-reset ui-widget-content">
                <tr>
                    <th style="width: 20%">@EWWebResources.Configuration_Route_Name</th>
                    <th>@EWWebResources.Configuration_Route_Value</th>
                    <th style="width: 20%"></th>
                </tr>
            </thead>
            <tbody class="ui-helper-reset ui-widget-content"></tbody>
            <tfoot class="ui-helper-reset ui-widget-content">
                <tr>
                    <td colspan="3"><a href="javascript:void(0)" class="easyweb-ewsimple-link-button">@EWWebResources.Configuration_Route_AddConstraint</a></td>
                </tr>
            </tfoot>
        </table>
    </div>
    <div>
        @Html.LabelFor(m => m.Value.Handler, EWWebResources.Configuration_Route_Handler)
        <input id="@Html.IdFor(m => m.Value.Handler)" name="@Html.NameFor(m => m.Value.Handler)" type="text" value="@(Model.Value.Handler == null ? null : Model.Value.Handler.AssemblyQualifiedName)" />
        @Html.ValidationMessageFor(m => m.Value)
    </div>
    <div>
        @using (Html.BeginRouteForm("EasyWeb_Configuration", FormMethod.Post, new { id = "easyweb-form-edit" }))
        {
            <input id="@Html.IdFor(m => m.Value)" name="@Html.NameFor(m => m.Value)" type="hidden" value="@EWDefaultWebApiRouteConfigurationModelBinder.ToJson(Model.Value)" />
            @Html.HiddenFor(m => m.Timestamp)
            <input id="easyweb-action-submit" type="submit" value="@EWWebResources.Button_Save" />
            <a id="easyweb-action-cancel" href="@Url.RouteUrl("EasyWeb_Admin")">@EWWebResources.Button_Cancel</a>
        }
    </div>
</fieldset>

@section head {
    <style type="text/css">
        .easyweb-ewroute label {
            display: block;
            margin: .5em 0;
        }

        .easyweb-ewroute div {
            margin: 1em 0;
        }

        #@Html.IdFor(m => m.Value.TemplateUrl), #@Html.IdFor(m => m.Value.Handler) {
            width: 50em;
        }
    </style>
}

@section scripts {
    <script type="text/javascript">
        (function ($) {
            $(function () {
                $("#easyweb-action-submit, #easyweb-action-cancel").button();

                EasyWeb.EWTemp.config = new EasyWeb.EWAdmin.EWDefaultWebApiRouteConfiguration(
                    $("#@Html.IdFor(m => m.Value.TemplateUrl)"),
                    $("#@Html.IdFor(m => m.Value.Handler)"),
                    $("#@Html.IdFor(m => m.Value.Defaults)"),
                    $("#@Html.IdFor(m => m.Value.Constraints)"),
                    null,
                    $("#@Html.IdFor(m => m.Value)"),
                    "@Url.RouteUrl("EasyWeb_Configuration", new { action = "RouteDefault" })",
                    "@Url.RouteUrl("EasyWeb_Configuration", new { action = "RouteConstraint" })",
                    "@Url.RouteUrl("EasyWeb_Configuration", new { action = "RouteNamespace" })",
                    "@EWWebResources.Button_Edit",
                    "@EWWebResources.Button_Delete",
                    "@EWWebResources.Window_Title_Message",
                    "@EWWebResources.Button_Ok",
                    "@EWWebResources.Button_Cancel",
                    "@EWWebResources.Button_Close",
                    "@EWWebResources.Window_Text_DefaultError",
                    function () {
                        EasyWeb.EWTemp.config.addRecord(EasyWeb.EWTemp.config, this);
                    },
                    function () {
                        EasyWeb.EWTemp.config.editRecord(EasyWeb.EWTemp.config, this);
                    },
                    function () {
                        EasyWeb.EWTemp.config.deleteRecord(EasyWeb.EWTemp.config, this);
                    }
                );
                EasyWeb.EWTemp.config.initialize();

                $("#easyweb-form-edit").submit(function () {
                    EasyWeb.EWTemp.config.refresh();
                });
            });
        })(jQuery);
    </script>
}